var express = require('express');
var router = express.Router();
var Post = require('../models/post');

/* POST 发步信息 */
router.post('/', function (req, res) {
  var currentUser = req.session.user;
  var post = new Post(currentUser.name, currentUser.nickname, req.body.post, new Date());

  post.save(function (err) {
    if (err) {
      req.flash('error', err);
      return res.redirect('/');
    }

    req.flash('success', '发表成功');
    res.redirect('/u/' + currentUser.name);
  });
});

module.exports = router;
